<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.autocomplete.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.autocomplete.js"></script>
<script type="text/javascript">
Refresh = function(){
	//jq的自动完成
	var swid = $("#start_warehouse").val();
	var ewid = $("#end_warehouse").val();
	$(".ajax_product").autocomplete("<?=url('Storage::Allocate/ProductInfoAjax')?>&start_warehouse_id="+swid+"&end_warehouse_id="+ewid).result(function(event, data, formatted){
		if (data[0])
		{
			var container = $(this).parent().parent();
			container.find("input[name$='product_basic_id]']").val(data['id']);
			container.find("input.available_quantity").val(data['available_quantity']);
			container.find("input[name$='quantity]']").val(data['quantity']);
		}
	});
	$(".button").click(function(){
		if ($(".quantity").val().length == 0)
		{
			alert("产品数量还没填写 !");
			return false;
		}
	});
};
$(function(){
	var i = 0;
	$("#add_product").click(function(){
		var _html = "<tr>";
		_html += "<td><input type='text' size='60' class='ajax_product' /><input type='hidden' name='item[new_" + i + "][product_basic_id]' /></td>";
		_html += "<td><input type='text' size='8' class='available_quantity' disabled='disabled' /></td>";
		_html += "<td><input type='text' size='8' name='item[new_" + i + "][quantity]' class='quantity' /></td>";
		_html += "<td><a href='javascript:void(0);' class='del_product'>删除产品</a></td>";
		_html += "</tr>";
		$("#list").append(_html);
		Refresh();
		i++;
	});
	$(".del_product").live("click", function(){
		if ( ! confirm("确定删除该产品？"))
		{
			return false;
		}
		else
		{
			$(this).parent().parent().remove();
		}
	});
	Refresh();
})

</script>
<form method="post" action="<?=url('Storage::Allocate/EditSave')?>">
<input type="hidden" name="warehouse_allocate_id" value="<?=$warehouse_allocate['id']?>" />
<table class="form_table">
<tr>
	<th>出库单号</th>
	<td><h3><?=$warehouse_allocate['number']?></h3></td>
</tr>
<tr>
	<th>制单时间</th>
	<td><?=$warehouse_allocate['make_time']?></td>
	<th>制单人员</th>
	<td><?=$warehouse_allocate['make_user_name']?></td>
</tr>
<tr>
	<th>起始仓</th>
	<td>
		<select name="start_warehouse_id" id="start_warehouse" disabled="disabled">
			<?foreach ($warehouse as $w):?>
			<option value="<?=$w['id']?>" <?if($warehouse_allocate['start_warehouse_id'] == $w['id'])echo "selected='selected'"?>><?=$w['name']?></option>
			<?endforeach;?>
		</select>
	</td>
	<th>目标仓</th>
	<td>
		<select name="end_warehouse_id" id="end_warehouse" disabled="disabled">
			<?foreach ($warehouse as $w):?>
			<option value="<?=$w['id']?>" <?if($warehouse_allocate['end_warehouse_id'] == $w['id'])echo "selected='selected'"?>><?=$w['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>备注</th>
	<td colspan="3"><textarea name="notes" cols="50" rows="4"><?=$warehouse_allocate['notes']?></textarea></td>
</tr>
</table>
<table width="80%" class="list_table"  id="list">
<tr>
	<th width="400">产品编号</th>
	<th width="80">可用库存</th>
	<th width="80">数量</th>
	<th width="100">操作</th>
</tr>
<?foreach ($item as $i):?>
<tr>
	<td><input type="text" size="60" class="ajax_product" value="<?=$i['product_number']?> <?=$i['product_name']?>" /><input type="hidden" name="item[<?=$i['id']?>][product_basic_id]" value="<?=$i['product_basic_id']?>" /></td>
	<td><input type="text" size="8" class="available_quantity" value="<?=$i['available_quantity']?>" disabled="disabled" /></td>
	<td><input type="text" size="8" class="quantity" name="item[<?=$i['id']?>][quantity]" value="<?=$i['quantity']?>" /></td>
	<td><a href="javascript:void(0);" class="del_product">删除产品</a></td>
</tr>
<?endforeach;?>
</table>
<a id="add_product">添加调拨单产品</a>
<div align="center"><input type="submit" class="button" value="确认" /><input type="hidden" name="<?=Q::ini('unique_token_name');?>" value="<?=Helper_BSS_Normal::genToken();?>"/></div>
</form>
<?php $this->_endblock();?>